#!/usr/bin/perl
=pod
vim:ts=4
=cut

# parameters to sweep
@nums = (2048);
@steps = (50);

# executable name of the baseline program
$base = "./seq/flock";

# executable names of the comparison programs
@execs = ("./omp/flock -l 5");

# number of trials to average
$trials = 5;

# auto print endlines
$\ = "\n";

# capture CTRL-C
$SIG{INT} = sub { exit(0); };

# file output
open FILE, ">", "test.txt" or die $!;

foreach $n(@nums) {
	foreach $s(@steps) {
		# multiplying the steps by 0.1 is a reasonable estimate for the time
		$t = 0.1 * $s;
		# get the base time for the serial version
		$basetime = 0;
		$_ = `$base -n $n -t $t -s $s -i ../inits/$n\lfish.out`;
		print($base);
		print($_);
		if (/Total time taken: ([\d\.]+)/) {
			$basetime = $1;
		}
		if ($basetime == 0) {
			die("Error: could not establish base time.");
		}
		# run the parallel versions and output the speedup
		foreach $e(@execs) {
			$time = 0;
			for ($i = 0; $i < $trials; $i++) {
				$_ = `$e -n $n -t $t -s $s -i ../inits/$n\lfish.out`;
				print($e);
				print($_);
				if (/Total time taken: ([\d\.]*)/) {
					$time += $1;
				}
			}
			$time /= $trials;
			$speedup = $basetime / $time;
			print FILE "$e\t$n\t$s\t$speedup";
		}
	}
}
